package com.example.c7.servlet;

import com.example.c7.bean.NewsBean;
import com.example.c7.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/newsDetail.html")
public class NewsDetailServlet  extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String newsID = req.getParameter("newsID");
        int id = Integer.parseInt(newsID);
        NewsBean newsBean = null;
        try {
            newsBean = (new NewsDao()).getNewsByID(id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("title", newsBean.getNewsTitle());
        req.setAttribute("content", newsBean.getNewsContent());
        req.getRequestDispatcher("newsDetail.jsp").forward(req, resp);
    }
}
